package com.hangxingliu.flashalarm;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SimpleAdapter extends BaseAdapter {

	private String[] dat;
	private Context context;
	
	public SimpleAdapter(Context context,String[] dat) {
		this.dat = dat;
		this.context = context;
	}
	
	public void setData(String[] dat){
		this.dat = dat;
		this.notifyDataSetInvalidated();
	}
	
	@Override
	public int getCount() {
		return dat.length;
	}

	@Override
	public Object getItem(int position) {
		if(position >= 0 && position < this.dat.length)
			return dat[position];
		else
			return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView v;
		if(convertView == null){
			v = new TextView(context);
			v.setTextSize(35.0f);
			v.setTextColor(Color.BLACK);
			v.setBackgroundColor(Color.WHITE);
		}else{
			v = (TextView) convertView;
		}
		v.setText(dat[position]);
		v.setTag(position);
		return v;
	}

}
